<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
    <title>获取对账邮件</title>
    <link rel="stylesheet" href="../../styles/h5/reset.min.css"/>
    <link rel="stylesheet" href="../../styles/h5/errortankuang.css"/>
    <!--以上为公共css样式-->
    <link rel="stylesheet" href="../../styles/h5/index.css"/>

    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery-1.9.1.min.js"></script>
    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery.modal.js"></script>
    <!--以上为公共js文件-->
</head>
<body>
<div class="zz-top"></div>
<div class="zz-list">
    <ul>
        <li>
            <span class="zz-left ">邮箱地址</span
            ><input class="zz-code-num zz-mail" type="text" placeholder="请输入接收账单的邮箱"/>
        </li>
        <li>
            <span class="zz-left">账单月份</span
            ><select class="zz-choice-month" name="" id=""></select>
            <span class="zz-right-arrow"></span>
        </li>
    </ul>
</div>

<input class="footer zz-footTop" type="button" value="确认">
</body>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/utils.js"></script>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/index.js"></script>
<script charset="utf-8" type="text/javascript">
    var queryURLParameter = utils.queryURLParameter();
    var merId = queryURLParameter.merId;
    //初始化月份
    $.ajax({
        url: utils.ajaxUrl()+"h5/billDetail/getBillMonths",
        async: false,
        type: 'get',
        success: function (res) {
        	var res = JSON.parse(res);
        	//console.log(res);
            if (res && res.retCode == '1') {
                var months = res["resultList"];
                var str = '';
                for (var i = 0; i < months.length; i++) {
                    var curMonths = months[i];
                    var yearMonths = curMonths.slice(0, 4) + "年" + curMonths.slice(4, 6) + "月";
                    str += '<option value="' + yearMonths + '">' + yearMonths + '</option>';
                }
                $(".zz-choice-month").html(str);
            } else {
            	$footer.attr("disabled", "true");
                new $.modal({
                    content: res.retMsg,//弹框内容
                    showcontent: true,//false为弹出框组件二，true为弹出框组件一
                }).show();
            }
        }
    });

    $footer.click(function () {
        var email = $(".zz-mail").val();
        if (!utils.effectiveMail(email, $footer)) {
            return false;
        }

        var billMonth = $(".zz-choice-month").val();
        billMonth = billMonth.slice(0, 4) + "" + billMonth.slice(5, 7);
        
        new $.modal({
            content: "加载中",
            animation: true//调用动画
        }).show();
        
        //$footer.attr("disabled", "true");
        $.ajax({
            url: utils.ajaxUrl()+"h5/billDetail/sendBillEmail",
            async: false,
            data: {
                email: email,
                billMonth: billMonth,
                merId: merId
            },
            type: 'get',
            success: function (res) {
            	var res = JSON.parse(res);
        		//console.log(res);
                if (res && res.retCode == '1') {
                	new $.modal({
            			animation: true,//调用动画
        			}).hide(0);
        			
                	new $.modal({
                    	content: "对账邮件将在3-5分钟后送达，请注意查收",//弹框内容
                    	showcontent: true,//false为弹出框组件二，true为弹出框组件一
                	}).show($footer,2000);
                	
                    setTimeout(function(){
                    	window.location.href = "../../html/h5/merchantMonthList.html";
                    	//$footer.removeAttr("disabled");
                    },2000);
                } else {
                	new $.modal({
            			animation: true,//调用动画
        			}).hide(0);
                    new $.modal({
                        content: res.retMsg,//弹框内容
                        showcontent: true,//false为弹出框组件二，true为弹出框组件一
                    }).show($footer);
                }
            }
        });
    })

</script>
</html>